//
//  BaseTableViewController.swift
//  Weibo
//
//  Created by Jet on 16/5/6.
//  Copyright © 2016年 Jet. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelagete{

    //标记用户是否登录
    var userLogin = UserAccountViewModel().userLogin
    var visitorLoginView:VisitorLoginView?
    
    
    /**
     loadView是苹果官方专门为手写代码准备的，　等效于sb/xib
     一旦实现这个方法　xib/sb就自动失效
     loadView会自动检测view是否为空　如果为空会自动调用loadView方法
     */
    override func loadView() {
        
        userLogin ? super.loadView() : loadVisitorView()
    }
    
   private func loadVisitorView()  {
    
      visitorLoginView = VisitorLoginView()
      visitorLoginView?.visitorDelegate = self
      view = visitorLoginView
    
      self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseTableViewController.visitorWillLogin))
      self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorWillRegister")
   
    }
    
    func visitorWillLogin() {
        print("登录")
        let oauthView = OAuthUIViewController()
       
        let nav = UINavigationController(rootViewController: oauthView)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    func visitorWillRegister() {
        print("注册")  
    }

    
}
